/**
 * 获取样式
 * @param {*} obj 
 * @param {*} attr 
 * @returns 
 */
function getStyle(obj, attr) {
    if (!window.getComputedStyle) {
        return obj.currentStyle[attr];
    } else {
        return window.getComputedStyle(obj, null)[attr];
    }
}
/**
 * 移动函数
 * @param {*} obj 
 * @param {*} attr 
 * @param {*} target 
 * @param {*} speed 
 * @param {*} callback 
 */
function moveTo(obj, attr, target, speed,callback) {
    clearInterval(obj.timer);
    obj.timer = setInterval(() => {
        let current = parseInt(getStyle(obj, attr));
        if (current<target?current>=target:current<=target) { 
            clearInterval(obj.timer);
            obj.style[attr] = target + "px";
            callback && callback();
        } else {
            obj.style[attr] = current + speed * (current<target?1:-1) + "px";
        }
    }, 10);
}